<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'user-add', //页面标示
    'pagename' => '添加帐号', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min','content/combodate/combodate','content/calendar'),
    'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="userForm">
              <div class="form-group">
                <label class="col-sm-1 control-label">帐户名</label>
                <div class="col-sm-3">
                  <input type="text" name="username" id="username" placeholder="" class="form-control" value="" />
                  <span class="help-block">帐户长度为2-30个字符</span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">密码</label>
                <div class="col-sm-3">
                  <input type="password" name="psw" id="psw" placeholder="" class="form-control" value="" />
                  <span class="help-block">密码长度必须大于4个字符</span></div>
                <div class="col-sm-3"></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">重复密码</label>
                <div class="col-sm-3">
                  <input type="password" name="repsw" id="repsw" placeholder="" class="form-control" value="" />
                  <span class="help-block"></span></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">帐号有效期</label>
                <div class="col-sm-2">
                  <input type="text" name="effective" id="effectiveeffective" placeholder="" class="form-control" value="" onClick="new Calendar().show(this);" readonly/>
                  <span class="help-block"></span></div>
                <div class="col-sm-3"></div>
              </div>
              <div class="form-group">
                <label class="col-sm-1 control-label">帐号组别</label>
                <div class="col-lg-2">
                  <select name="groupid" id="groupid" class="form-control">
                   <?php
				   foreach($group as $key=>$val){
				   ?>
                    <option value="<?php echo $key;?>"><?php echo $val;?></option>
                    <?php
				   }
				   ?>
                  </select>
                </div>
              </div>
              <div class="form-group" id="show-area" style="display:none">
                <label class="col-sm-1 control-label">管理区域</label>
                <div class="col-sm-3">
                  <input type="text" name="group_name" id="group_name" placeholder="" class="form-control" value="" readonly="readonly" />
                  <span class="help-block"></span></div>
                  <div class="col-sm-3">
                  <a href="javascript:;" class="btn btn-default" id="select-area" rel="pop">设定区域</a>
                  <a href="javascript:;" class="clear-area btn btn-default search-area col-md-offset-1" rel="group">清除</a>
                  </div>
              </div>
              <div class="form-group" id="show-village" style="display:none">
                <label class="col-sm-1 control-label">管理小区</label>
                <div class="col-sm-3">
                  <input type="text" name="village_name" id="village_name" placeholder="" class="form-control" value="" readonly="readonly" />
                  <input type="hidden" name="village_id" id="village_id" placeholder="" class="form-control" value=""/>
                  <span class="help-block"></span></div>
                  <div class="col-sm-3">
                  <a href="<?php echo U('village/search');?>" class="btn btn-default" rel="pop">设定小区</a>
                  <a href="javascript:;" class="clear-area btn btn-default search-area col-md-offset-1" rel="village">清除</a>
                  </div>
              </div>
              <div class="form-group">
                <div class="col-sm-9 col-lg-offset-1">
                  <div class="col-sm-1">
                  	<input type="hidden" name="aid" id="aid" placeholder="" class="form-control" value="0" />
                    <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                  </div>
                  <div class="col-md-offset-2">
                    <button type="button" class="btn btn-white">取消</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<!--主体 结束--> 
<script>
function setArea(aid,aname){
		console.log(aid);
		console.log(aname);
		$("#aid").val(aid);
		$("#group_name").val(aname);
		$(document).trigger('close.facebox');
}
function setVillage(vid,aname,aid){
		console.log(vid);
		console.log(aname);
		console.log(aid);
		$("#aid").val(aid);
		$("#village_id").val(vid);
		$("#village_name").val(aname);
		$(document).trigger('close.facebox');
}
$(function(){
	var areaType=1;//区域级别 0:社区 1:街道 2:城区
	var groupid=$.trim($("#groupid").val());
	$('#userForm').submit(function(){
		var username=$.trim($("#username").val());
		var psw=$.trim($("#psw").val());
		var repsw=$.trim($("#repsw").val());
		var aid=$.trim($("#aid").val());
		var village_id=$.trim($("#village_id").val());
		console.log(groupid)
		var isOk=true;
		if (!username){
			Msg.error('帐户名不能为空');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		if (!psw||!repsw){
			Msg.error('密码不能为空');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		if (psw!=repsw){
			Msg.error('密码输入不一致');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		Msg.loading();
		  $.post('<?php echo U('user/post');?>',$(this).serialize(),function(result){
			  Msg.hide();
			  resetSubmit("#sub-ok",'保存');
			  if (result.status==1){
				Msg.ok('添加成功',function(){
					document.location='<?php echo U('user/index');?>';	
				},3000);  
			}else{
				Msg.error(result.info);
			}
		  },'json');
		  return false;
	})
	// $("#groupid").change(function(){
	// 	groupid=$(this).val();
	// 	switch(groupid){
	// 		case '1':
	// 		$("#show-area").hide();
	// 		$("#show-village").hide();
	// 		break;
	// 		case '2':
	// 		areaType=1;
	// 		$("#show-area").show();
	// 		$("#show-village").hide();
	// 		break;
	// 		case '3':
	// 		areaType=0;
	// 		$("#show-area").show();
	// 		$("#show-village").hide();
	// 		break;
	// 		case '4':
	// 		$("#show-area").hide();
	// 		$("#show-village").show();
	// 		break;
	// 	}
	// });
	$(".clear-area").click(function(){
		var t=$(this).attr("rel");
		$("#"+t+'_name').val('');
		if (t=='village'){
			$("#village_id").val('');
		}else{
			$("#aid").val('');
		}
		return false;
	})
	$("#select-area").click(function(){
		$(this).attr('href','<?php echo U('area/search',array(),true);?>&type='+areaType);
	})
})
</script>
<?php
include getTpl('footer', 'public');
?>